let baseReg = /^.*?(?=[^\/]*(\?|$))/;
let absoluteReg = /^(\w+:\/\/|\/)/;
let onlineReg = /^((http|https):\/\/|\/)/;

export const urlUtils = {
    getBase: (url) => {
        return (url) ? baseReg.exec(url)[0] : '';
    },
    isAbsolute: (url) => {
        return absoluteReg.test(url);
    },
    isHttpAddress: (url) => {
        return onlineReg.test(url);
    },
    resolve: (base, url) => {
        if (arguments.length === 1) {
            url = base;
            base = urlUtils.getBaseLocationUrl();
        }
        return urlUtils.isAbsolute(url) ? url : base + '/' + url;
    },
    getBaseLocationUrl: () => {
        let url = urlUtils.getBase(location.href);
        urlUtils.getBaseLocationUrl = function () {
            return url;
        };
        return this.getBaseLocationUrl();
    }
};